export default {
  data() {
    const validateUserName = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入姓名'));
      } else {
        callback();
      }
    };
    const validateAcronym = (rule, value, callback) => {
      if (!value) {
        callback(new Error('请输入拼音缩写'));
      } else if (/^[a-z]+$/.test(value) === false) {
        callback(new Error('请输入小写字母'));
      } else {
        callback();
      }
    };
    const validatePassword = (rule, value, callback) => {
      if (this.isShow) {
        if (!this.editUserForm.oldPwd) {
          callback(new Error('请先填写原密码'));
        } else if (!value) {
          callback(new Error('密码不能少于6位'));
        } else if (value.length < 6) {
          callback(new Error('密码不能少于6位'));
        } else {
          if (this.editUserForm.rePassword !== '') {
            this.$refs.editUserForm.validateField('rePassword');
          }
          callback();
        }
      } else {
        if (!value) {
          callback(new Error('密码不能少于6位'));
        } else if (value.length < 6) {
          callback(new Error('密码不能少于6位'));
        } else {
          if (this.editUserForm.rePassword !== '') {
            this.$refs.editUserForm.validateField('rePassword');
          }
          callback();
        }
      }
    };
    const validateRePassword = (rule, value, callback) => {
      if (this.isShow) {
        if (!this.editUserForm.oldPwd) {
          callback(new Error('请先填写原密码'));
        } else if (!this.editUserForm.password) {
          callback(new Error('请先填写新密码'));
        } else if (!value) {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.editUserForm.password) {
          callback(new Error('两次输入密码不一致'));
        } else {
          callback();
        }
      } else {
        if (!this.editUserForm.password) {
          callback(new Error('请先填写密码'));
        } else if (!value) {
          callback(new Error('请再次输入密码'));
        } else if (value !== this.editUserForm.password) {
          callback(new Error('两次输入密码不一致'));
        } else {
          callback();
        }
      }
    };
    return {
      isShow: false,
      editUserRules: {
        userName: [{ required: true, trigger: 'blur', validator: validateUserName }],
        acronym: [{ required: true, trigger: 'blur', validator: validateAcronym }],
        jobNumber: [{ required: true, trigger: 'blur', message: '请输入工号' }],
        oldPwd: [{ required: true, trigger: 'blur', message: '请输入原密码' }],
        password: [{ required: true, trigger: 'blur', validator: validatePassword }],
        rePassword: [{ required: true, trigger: 'blur', validator: validateRePassword }],
        email: [{ required: true, trigger: 'blur', type: 'email', message: '请输入正确的邮箱地址' }],
        departmentAry: [{ required: true, trigger: 'change', message: '请选择部门' }]
      }
    };
  }
};
